﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;

using TarreOA.TarreOAModels;
namespace TarreOA.TarreOADAL
{
    public class Tel_PostDAO
    {
        public List<post_tel> FindTel(string area)
        {
            List<post_tel> list = new List<post_tel>();
            SqlConnection conn = null;
            try
            {
                conn = SQLManager.GetConn();
                SqlCommand sc = new SqlCommand();
                sc.Connection = conn;
                sc.CommandText = "select * from post_tel where area='" + area + "'";
                conn.Open();
                SqlDataReader dr = sc.ExecuteReader();
                while (dr.Read())
                {
                    post_tel pt = new post_tel();
                   
                    pt.Area=(string)dr["area"];

                    pt.Post_no = (string)dr["post_no"];
                    if (pt.Post_no.Equals("NULL"))
                    {
                        pt.Post_no = "10000";
                    }

                    pt.Province = (string)dr["province"];
                    if (pt.Equals("1")) {
                        pt.Province = "大洋洲";
                    }
                    if (pt.Equals("0"))
                    {
                        pt.Province = "黑龙江";
                    }
                    if (pt.Equals("2"))
                    {
                        pt.Province = "内蒙古";
                    }

                    pt.Tel_no = (string)dr["tel_no"];
                    list.Add(pt);
                }
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
            }
            finally
            {
                if (conn.State == ConnectionState.Open)
                {
                    conn.Close();
                }
            }
            return list;



        }
        public List<post_tel> FindByTel(string area)
        {
            List<post_tel> list = new List<post_tel>();
            SqlConnection conn = null;
            try
            {
                conn = SQLManager.GetConn();
                SqlCommand sc = new SqlCommand();
                sc.Connection = conn;
                sc.CommandText = "select * from post_tel where area='" + area + "'";
                conn.Open();
                SqlDataReader dr = sc.ExecuteReader();
                while (dr.Read())
                {
                    post_tel pt = new post_tel();

                    pt.Area = (string)dr["area"];

                    pt.Post_no = (string)dr["post_no"];
                    if (pt.Post_no.Equals("NULL"))
                    {
                        pt.Post_no = "10000";
                    }
                    pt.Province = (string)dr["province"];
                    if (pt.Equals("1"))
                    {
                        pt.Province = "大洋洲";
                    }
                    if (pt.Equals("0"))
                    {
                        pt.Province = "黑龙江";
                    }
                    if (pt.Equals("2"))
                    {
                        pt.Province = "内蒙古";
                    }
                    pt.Tel_no = (string)dr["tel_no"];
                    list.Add(pt);
                }
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
            }
            finally
            {
                if (conn.State == ConnectionState.Open)
                {
                    conn.Close();
                }
            }
            return list;
        }
    }
}
